package cn.com.connected.common.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.context.ApplicationListener;
import cn.com.connected.base.exception.ErrorLogRobot;

/**
 * 作者:   邵明生
 * 时间:   2019/5/5 13:45
 * 描述:   项目启动失败
 */
public class StartFailListener implements ApplicationListener<ApplicationFailedEvent> {
    private static Logger logger = LoggerFactory.getLogger(StartFailListener.class);

    @Value("${server.name}")
    private String applicationName;

    @Value("${spring.profile.active}")
    private String profile;

    @Override
    public void onApplicationEvent(ApplicationFailedEvent applicationFailedEvent) {
        String messageBody = " 启动失败";
        logger.error(messageBody);
        Throwable t = applicationFailedEvent.getException();
        logger.error("项目启动报错",t);
        ErrorLogRobot.sendError2DingDing( messageBody+"/n"+t.getMessage());

    }
}